using System.Collections.Specialized;
using System.Text;
using Basmus.ReadWrite;
using Basmus.Values;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Basmus.Tests.WebLink
{
    [TestClass]
    public abstract class AbstractValueProviderTests<T> where T : IValuesProvider<string>
    {
        protected abstract void SetStringValues(string name, string values);

        protected abstract T GetValueProvider();

        [TestMethod]
        public void GetValues_WithoutValues_ReturnNull()
        {
            //Act
            var values = GetValueProvider().GetValues("AnyName1");

            //Assert
            Assert.IsNull(values);
        }

        [TestMethod]
        public void GetValues_SingleValueByCorrespondingName_ReturnThisValue()
        {
            //Arrange
            SetStringValues("Name1", "dfdsf22");

            //Act
            var values = GetValueProvider().GetValues("Name1");

            //Assert
            CollectionAssertHelper.AreEqual(new[] { "dfdsf22" }, values);
        }

        [TestMethod]
        public void GetValues_SingleValueWithSpacesByCorrespondingName_ReturnThisValueWithSpaces()
        {
            //Arrange
            SetStringValues("Name1", " dfdsf22  ");

            //Act
            var values = GetValueProvider().GetValues("Name1");

            //Assert
            CollectionAssertHelper.AreEqual(new[] { " dfdsf22  " }, values);
        }

        [TestMethod]
        public void GetValues_SingleValueByWrongName_ReturnNull()
        {
            //Arrange
            SetStringValues("Name1", "dfdsf22");

            //Act
            var values = GetValueProvider().GetValues("WrongName1");

            //Assert
            Assert.IsNull(values);
        }

        [TestMethod]
        public void GetValues_MultipleValuesByCorrespondingName_ReturnTheseValues()
        {
            //Arrange
            SetStringValues("Value2", "AAAA,_444_,222");

            //Act
            var values = GetValueProvider().GetValues("Value2");

            //Assert
            CollectionAssertHelper.AreEqual(new[] { "AAAA", "_444_", "222" }, values);
        }

        [TestMethod]
        public void GetValues_MultipleValuesWithSpacesByCorrespondingName_ReturnTheseValuesWithSpaces()
        {
            //Arrange
            SetStringValues("Value2", "  AAAA,  _444_ ,222 ");

            //Act
            var values = GetValueProvider().GetValues("Value2");

            //Assert
            CollectionAssertHelper.AreEqual(new[] { "  AAAA", "  _444_ ", "222 " }, values);
        }

        [TestMethod]
        public void GetValues_EmptyByCorrespondingName_ReturnEmpty()
        {
            //Arrange
            SetStringValues("Name1", "");

            //Act
            var values = GetValueProvider().GetValues("Name1");

            //Assert
            CollectionAssertHelper.AreEqual(new[] { "" }, values);
        }
    }
}